package com.power.sifa.correction.dao;

import com.power.sifa.correction.model.Crc_camera;
import com.power.sifa.correction.model.Cre_work;
import com.power.sifa.correction.model.pageInfo.Cre_warningPageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.correction.model.Cre_warning;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 预警信息 持久层(hibernate)
 */

public interface Cre_warningDao extends JpaRepository<Cre_warning, Serializable>, JpaSpecificationExecutor<Cre_warning>, Repository<Cre_warning, Serializable>, Cre_warningDaoCustom<Cre_warning, Serializable> {

    @Modifying
    @Transactional
    @Query("delete  from Cre_warning s where  s.id in (:ids) ")
    void removeByIds(@Param("ids") List<Integer> ids);

    /**
     * 更新督办状态
     *
     * @param id
     * @param issup
     */
    @Modifying
    @Transactional
    @Query("update Cre_warning s set s.issup = :issup where  s.id = :id")
    void updateIssup(String id, Integer issup);

    /**
     * 更新再办状态
     *
     * @param id
     * @param isrepeat
     */
    @Modifying
    @Transactional
    @Query("update Cre_warning s set s.isrepeat = :isrepeat where  s.id = :id")
    void updateIsrepeat(String id, Integer isrepeat);

    /**
     * 批量更新督办状态
     *
     * @param ids
     * @param issup
     */
    @Modifying
    @Transactional
    @Query("update Cre_warning s set s.issup = :issup where  s.id in (:ids)")
    void updateIssup(List<String> ids, Integer issup);

    /**
     * 根据人员id查询预警记录
     *
     * @param perid
     * @return
     */
    @Query(" from Cre_warning s where  s.perid = :perid ")
    List<Cre_warning> findListByPerid(String perid);

    @Query("select cw from Cre_warning cw where 1 = 1 and cw.type in (:fType) order by cw.rectime desc")
    Page<Cre_warning> findByType(List<Integer> fType, Pageable pageable);

    @Query("select c from Cre_warning c left join Cre_work w on c.id = w.warnid where 1 = 1 and w.status in (:status)")
    List<Cre_warning> findListByWorkStatus(List<Integer> status);

    @Query("select count(*) from Cre_warning w left join Cre_work k on w.id = k.warnid where concat(w.latcamera, ',', w.lngcamera) = :latlng group by k.status having k.status = :status")
    Long countCarmeraDealTotal(String latlng, Integer status);

//   @Query("select * from cre_warning where perid = '2023032201'")
//   Cre_warning findByWarnid(String warnid);
}
